package com.bjpowernode.p2p.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.bjpowernode.common.constant.Constants;
import com.bjpowernode.p2p.mapper.loan.BidInfoMapper;
import com.bjpowernode.p2p.model.loan.BidInfo;
import com.bjpowernode.p2p.service.BInfoService;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * ClassName:BInfoServiceImpl
 * Package:com.bjpowernode.p2p.service.impl
 * Description: 描述信息
 *
 * @date:2021/7/16 14:03
 * @author:动力节点
 */

@Component
@Service(interfaceClass = BInfoService.class,version = "1.0-SNAPSHOT",timeout = 15000)
public class BInfoServiceImpl implements BInfoService {
    @Autowired
    private BidInfoMapper bidInfoMapper;
    @Autowired
    private RedisTemplate<Object,Object> redisTemplate;

    @Override
    public Double queryAllMoney() {
        Double allMoney = (Double) redisTemplate.opsForValue().get(Constants.ALL_MONEY);
        if(!ObjectUtils.allNotNull(allMoney)){
            synchronized (this){
                allMoney = (Double) redisTemplate.opsForValue().get(Constants.ALL_MONEY);
                if(!ObjectUtils.allNotNull(allMoney)){
                    allMoney = bidInfoMapper.selectAllMoney();
                    redisTemplate.opsForValue().set(Constants.ALL_MONEY,allMoney);
                }
            }
        }
        return allMoney;
    }

    @Override
    public List<BidInfo> queryUserByPruductId(String id) {
        return bidInfoMapper.selectBidInfoByProductId(id);
    }



    @Override
    public List<BidInfo> queryBidInfoByStatus(Integer statusOne) {
        return bidInfoMapper.selectAllBinfoByStatus(statusOne);
    }

    @Override
    public List<BidInfo> queryBidInfo() {
       return bidInfoMapper.selectBidInfo();
    }
}
